<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>for循环练习</title>
    <script>
        /* for循环练习 */
        /* 
        打印1-100之间的所有奇数之和
        */
        var result = 0;
        for (var a = 1; a <= 100; a++) {
            if (a % 2 != 0) {
                result = result + a;
            }
        }
        document.write("1-100所有的奇数和为：" + result + "<br/>");
        /* 
        打印1-100之间所有7的倍数的个数以及总和
        */
        var sum = 0,
            num = 0;
        for (var i = 1; i <= 100; i++) {
            if (i % 7 == 0) {
                sum = sum + i;
                document.write(i + "<br/>");
                num++;
            }
        }
        document.write("1-100所有7的倍数个数为：" + num + ",总和为：" + sum + "<br/>");


        /* 水仙花数 */
        /* for (var c = 100; c < 1000; c++) {
            var b = c / 100;
            var n = c % 100 / 10;
            var m = c % 10;
            if (b * b * b + n * n * n * n + m * m * m == c) {
                document.write("水仙花数为：" + c + "<br/>")
            }
        } */
        //打印所有的三位数
        for (var k = 100; k < 1000; k++) {
            //获取k的百位，十位，个位数字
            var bai = parseInt(k / 100);
            var shi = parseInt(k % 100 / 10);
            var ge = k % 10;
            //判断i是否为水仙花数
            if (bai * bai * bai + shi * shi * shi + ge * ge * ge == k) {
                document.write("水仙花数为：" + k + "<br/>")
            }
        }
    </script>
</head>

<body>

</body>

</html>